import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:geomancy/providers/user_provider.dart';
import 'package:geomancy/styles/index.dart';
import 'package:geomancy/tools/constant.dart';
import 'package:geomancy/widgets/common_btn.dart';
import 'package:geomancy/widgets/common_header.dart';
import 'package:geomancy/widgets/common_input.dart';
import 'package:geomancy/widgets/common_text.dart';
import 'package:geomancy/widgets/stroke_text.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';

class RegisterNicknamePage extends StatefulWidget {
  const RegisterNicknamePage({super.key});

  @override
  State<RegisterNicknamePage> createState() => _RegisterNicknamePageState();
}

class _RegisterNicknamePageState extends State<RegisterNicknamePage> {
  String nickname = '';

  void getValue(String value) {
    setState(() {
      nickname = value;
    });
  }

  void nextHandle() {
    if (nickname == '') {
      return;
    }
    context.read<UserProvider>().setNickname = nickname;
    context.push('/register_sex');
  }

  @override
  Widget build(BuildContext context) {
    final bool disabled = nickname == '';
    return Scaffold(
      appBar: CommonHeader.appBar(context: context, showActions: false),
      backgroundColor: ColorStyle.pageDefaultColor,
      resizeToAvoidBottomInset: false,
      body: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: Container(
          width: double.infinity,
          padding: EdgeInsets.only(top: 100.w, left: Constant.PAGEPADDING.w, right: Constant.PAGEPADDING.w),
          child: DottedBorder(
            borderType: BorderType.RRect,
            strokeWidth: 5.w,
            radius: Radius.circular(60.w),
            dashPattern: [12.w, 6.w],
            color: ColorStyle.borderColor,
            child: Container(
              width: double.infinity,
              height: 1050.w,
              padding: EdgeInsets.only(top: 110.w, bottom: 60.w),
              decoration: BoxDecoration(
                color: ColorStyle.themeLightColor,
                borderRadius: BorderRadius.all(Radius.circular(55.w)),
              ),
              child: Column(
                children: [
                  StrokeText(txt: '设置昵称', strokeWidth: 8.sp, fontSize: 60.sp, color: ColorStyle.themeColor, fontFamily: 'fontZKKLT'),
                  SizedBox(height: 130.w),
                  CommonInputWidget(
                    size: Size(510.w, 100.w),
                    hintText: '请输入昵称',
                    maxLength: 10,
                    addonAfter: CommonText(txt: '（${nickname.length}/10）'),
                    getValue: getValue
                  ),
                  const Expanded(child: SizedBox()),
                  CommonBtnWidget(size: Size(510.w, 100.w), disabled: disabled, txt: '下一步', onTap: nextHandle)
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
